<template>
  <tree-select
    ref="treeSelect"
    @treeSelect="handleSelect"
    :selectStyle="selectStyle"
    :options="deptTreeData"
    :selectValue="selectValue"
    :disabled="disabled"
  />
</template>

<script>
import TreeSelect from '@/components/ETreeSelect'
// import { getSession } from '@/utils/util'

export default {
  components: {
    TreeSelect
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    selectValue: {
      type: String,
      default: ''
    },
    selectStyle: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  mounted() {
    this.deptTreeData = this.handleData(this.$ls.get('dictionaryData'))
  },
  data() {
    return {
      deptTreeData: []
    }
  },
  methods: {
    handleData(arr) {
      arr.map(v => {
        v.id = v.key
        v.label = v.title
        if (v.children.length > 0) {
          this.handleData(v.children)
        } else {
          delete v.children
        }
      })
      return arr
    },
    reset() {
      this.$refs.treeSelect.reset()
    },
    handleSelect(value) {
      this.$emit('select', value)
    }
  }
}
</script>
